import axios from 'axios';

const myaxios = {};

myaxios.install = function (Vue) {

  const myAxiosObj = axios.create({
    baseURL: 'http://localhost:8888/api/private/v1'
  });

  myAxiosObj.interceptors.request.use(function (config) {
    // 在发送请求之前做些什么
    if (config.url !== '/login') {
      // 登录之后才能获取token
      var token = JSON.parse(localStorage.getItem('userinfo')).token
      config.headers.Authorization = token
    }
    return config
  });

  Vue.prototype.$req = myAxiosObj

}

export default myaxios